#include "CDrawingBoardWidget.h"
#include <QWidget>

CDrawingBoardWidget::CDrawingBoardWidget(QWidget *parent) : QWidget(parent)
{
    m_BlackPenBtn.setParent(this);
    m_BlackPenBtn.setText(QStringLiteral("黑画笔"));
    m_BlackPenBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Brushhuabi.png")));
    m_BlackPenBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_BlackPenBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_RadPenBtn.setParent(this);
    m_RadPenBtn.setText(QStringLiteral("红画笔"));
    m_RadPenBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Brushhuabi-2.png")));
    m_RadPenBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_RadPenBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_BluePenBtn.setParent(this);
    m_BluePenBtn.setText(QStringLiteral("蓝画笔"));
    m_BluePenBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Brushhuabi-3.png")));
    m_BluePenBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_BluePenBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_RectangleBtn.setParent(this);
    m_RectangleBtn.setText(QStringLiteral("矩形"));
    m_RectangleBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Rectangle.png")));
    m_RectangleBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_RectangleBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_EllipseBtn.setParent(this);
    m_EllipseBtn.setText(QStringLiteral("椭圆"));
    m_EllipseBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Ellipse.png")));
    m_EllipseBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_EllipseBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_PentagonBtn.setParent(this);
    m_PentagonBtn.setText(QStringLiteral("五边形"));
    m_PentagonBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/pentagon.png")));
    m_PentagonBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_PentagonBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_TriangleBtn.setParent(this);
    m_TriangleBtn.setText(QStringLiteral("等腰三角形"));
    m_TriangleBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Triangle.png")));
    m_TriangleBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_TriangleBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_LineBtn.setParent(this);
    m_LineBtn.setText(QStringLiteral("直线"));
    m_LineBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/Line.png")));
    m_LineBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_LineBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);


    m_RotateLeftBtn.setParent(this);
    m_RotateLeftBtn.setText(QStringLiteral("左旋转"));
    m_RotateLeftBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/LeftRotate.png")));
    m_RotateLeftBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_RotateLeftBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_RotateRightBtn.setParent(this);
    m_RotateRightBtn.setText(QStringLiteral("右旋转"));
    m_RotateRightBtn.setIcon(QIcon(QString(":/Icon/Resource/Icon/RightRotate.png")));
    m_RotateRightBtn.setIconSize(QSize(ICON_SIZE, ICON_SIZE));
    m_RotateRightBtn.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    m_DrawWidget.setParent(this);

    QObject::connect(&m_RectangleBtn,    &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_RectangleBtn_Clicked,    Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_EllipseBtn,      &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_EllipseBtn_Clicked,      Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_TriangleBtn,     &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_TriangleBtn_Clicked,     Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_LineBtn,         &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_LineBtn_Clicked,         Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_RotateLeftBtn,   &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_RotateLeftBtn_Clicked,   Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_RotateRightBtn,  &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_RotateRightBtn_Clicked,  Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_BlackPenBtn,     &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_BlackPenBtn_Clicked,     Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_RadPenBtn,       &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_RadPenBtn_Clicked,       Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_BluePenBtn,      &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_BluePenBtn_Clicked,      Qt::ConnectionType::DirectConnection);
    QObject::connect(&m_PentagonBtn,     &QToolButton::clicked,this,&CDrawingBoardWidget::fn_Recv_PentagonBtn_Clicked,     Qt::ConnectionType::DirectConnection);


}

CDrawingBoardWidget::~CDrawingBoardWidget()
{
}

void CDrawingBoardWidget::resizeEvent(QResizeEvent *event)
{
    m_RotateLeftBtn.setGeometry (BTN_SIZE*3, 0         , BTN_SIZE,  BTN_SIZE);
    m_RotateRightBtn.setGeometry(BTN_SIZE*4, 0,          BTN_SIZE,  BTN_SIZE);
    m_RectangleBtn.setGeometry  (0         , BTN_SIZE*1, BTN_SIZE,  BTN_SIZE);
    m_EllipseBtn.setGeometry    (0         , BTN_SIZE*2, BTN_SIZE,  BTN_SIZE);
    m_TriangleBtn.setGeometry   (0         , BTN_SIZE*3, BTN_SIZE,  BTN_SIZE);
    m_LineBtn.setGeometry       (0         , BTN_SIZE*4, BTN_SIZE,  BTN_SIZE);
    m_BlackPenBtn.setGeometry   (BTN_SIZE*0, 0         , BTN_SIZE,  BTN_SIZE);
    m_RadPenBtn.setGeometry     (BTN_SIZE*1, 0         , BTN_SIZE,  BTN_SIZE);
    m_BluePenBtn.setGeometry    (BTN_SIZE*2, 0         , BTN_SIZE,  BTN_SIZE);
    m_PentagonBtn.setGeometry   (0         ,BTN_SIZE*5 , BTN_SIZE,  BTN_SIZE);


    m_DrawWidget.setGeometry    (BTN_SIZE+5, BTN_SIZE+5, width() - 10, height() - BTN_SIZE - 10);



    QWidget::resizeEvent(event);
}

int CDrawingBoardWidget::fn_Recv_RectangleBtn_Clicked()
{
    m_DrawWidget.SetShapeType(ShapeType::Shape_Rectangle);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_EllipseBtn_Clicked()
{
    m_DrawWidget.SetShapeType(ShapeType::Shape_Ellipse);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_TriangleBtn_Clicked()
{
    m_DrawWidget.SetShapeType(ShapeType::Shape_Triangle);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_LineBtn_Clicked()
{
    m_DrawWidget.SetShapeType(ShapeType::Shape_Line);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_RotateLeftBtn_Clicked()
{
    m_DrawWidget.RotateLeft();
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_RotateRightBtn_Clicked()
{
    m_DrawWidget.RotateRight();
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_BlackPenBtn_Clicked()
{
    m_DrawWidget.SetPenColor(PenColor::Color_Black);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_RadPenBtn_Clicked()
{
    m_DrawWidget.SetPenColor(PenColor::Color_Rad);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_BluePenBtn_Clicked()
{
    m_DrawWidget.SetPenColor(PenColor::Color_Blue);
    return NORMAL_RETURN;
}

int CDrawingBoardWidget::fn_Recv_PentagonBtn_Clicked()
{
    m_DrawWidget.SetShapeType(ShapeType::Shape_Pentagon);
    return NORMAL_RETURN;
}
